# 7.1
fdict = dict((['x', 1], ['y', 2]))
print(fdict)

ddict = {}.fromkeys(('x', 'y'), -1)
print(ddict)

ndict = {}.fromkeys(('x', 'y'))
print(ndict)

dict2 = {'name': 'earth', 'port': 80}
for key in dict2:
    print('key=%s, value=%s' % (key, dict2[key]))
del dict2['name']
print(dict2)
dict2.clear()
print(dict2)

# 7.3
adict = dict(zip(('x', 'y'), (1, 2)))
print(adict)
adict = dict([['x', 1], ['y', 2]])
print(adict)
print(dict([('xy'[i - 1], i) for i in range(1, 3)]))
dict8 = dict(x=1, y=2)
print(dict8)
dict9 = dict(**dict8)
print(dict9)
dict9 = dict8.copy()
print(dict9)
print(hash((1, 2)))
print(dict9.keys(), dict9.values())
dict9.update({'y': 8, 'z': 9})
print(dict9)

# 7.4
print(dict9.get('x'))
print(dict9.get('a', 123))
dict9.setdefault('port', 80)
print(dict9.keys(), dict9.items())
